<template>
  <!-- 招才管理 -->
  <div class="box">
    <heads></heads>
    <titlesearch></titlesearch>
    <div class="gerenBox">
      <ceList :index="35"></ceList>
      <template v-if="!showDetail">
        <div class="con">
          <div class="one-tab no-padding">
            <div class="one-tab-left">
              <div class="one-tab-item" :class="tabIndex == item.num ? 'active' : ''"
                @click="(tabIndex = item.num), tabClick(item.num)" v-for="(item, index) in list" :key="index">
                {{ item.text }}
              </div>
            </div>
            <div class="one-tab-right">
              <!-- <template v-if="tabIndex == 1">
                <div class="one-tab-right-search-wrap" id="one-tab-right-search-wrap">
                  <input type="text" v-model="searchKeyword" class="one-tab-right-search-input" />
                  <img src="@/assets/v3/new-search.png" alt="" class="one-tab-right-search-img" @click="getRecommend" />
                </div>
              </template>
              <template v-if="tabIndex == 3">
                <div class="one-tab-right-search-wrap" id="one-tab-right-search-wrap">
                  <input type="text" v-model="searchKeyword" class="one-tab-right-search-input" />
                  <img src="@/assets/v3/new-search.png" alt="" class="one-tab-right-search-img" @click="getRecommend" />
                </div>
              </template> -->
              <template v-if="manage">
                <div class="one-tab-right-btn" @click="manage = false">
                  取消
                </div>
                <div class="one-tab-right-btn" @click.stop="clearAll">删除</div>
              </template>
              <template v-else>
                <div class="one-tab-right-btn" @click="manage = !manage">
                  管理
                </div>
              </template>
            </div>
          </div>
          <!-- <div class="list">
            <recommended v-for="(item, index) in 10" :key="index"></recommended>
          </div> -->
          <template v-if="msgtotal > 0">
            <div class="list">
              <div class="li" v-for="(item, index) in Recommend">
                <div class="box-check invite" v-show="manage">
                  <el-checkbox :value="item.choose" @change="choosehouse(item.id)"></el-checkbox>
                </div>
                <template v-if="tabIndex != 2">
                  <recommended :key="index" :mode="tabIndex == 1 ? 'own' : ''" :item="item" customEvent
                    @details="detail(item)"></recommended>
                </template>
                <template v-if="tabIndex == 2">
                  <invite-item :key="index" :mode="tabIndex == 1 ? 'own' : ''" :item="item.recruitmentInformationDTO" line
                    customEvent @resumeHistory="detail(item, index)" @details="detail(item)"></invite-item>
                </template>
              </div>
            </div>
            <div class="fenye">
              <el-pagination background layout="prev, pager, next" :total="msgtotal" :current-page="msgpage.pageNo"
                :page-size="msgpage.pageSize" @current-change="msgCurrentChange"></el-pagination>
            </div>
          </template>
          <div class="con" v-else>
            <div class="li" style="margin-top: 100px; margin-bottom: 100px">
              <el-empty description="暂无数据"></el-empty>
            </div>
          </div>

          <!-- <div class="caozuo" v-if="manage">
            <el-checkbox v-model="select" @change="selectColl">{{
              select ? "取消全选" : "全选"
            }}</el-checkbox>
          </div> -->
        </div>
      </template>
      <template v-else>
        <div class="con">
          <div class="one-tab" style="margin: 0">
            <div class="one-tab-left">
              <i class="one-tab-back el-icon-arrow-left" @click.stop="showDetail = false, getRecommend(true)"></i>
              <div class="one-tab-text line1" v-if="tabIndex == 1 && data.recruitmentInformationDTO">
                投递职位：{{ data.recruitmentInformationDTO.title }}
              </div>
            </div>
            <div class="one-tab-right" @click.stop="clearAll">
              <div class="one-tab-right-btn">删除</div>
            </div>
          </div>
          <div class="one-detail">
            <img :src="$resmeUpload + data.pictureAttachment" alt="" srcset="" class="one-detail-img" />
            <div class="one-detail-btn-wrap">
              <div class="one-detail-btn active" @click="mouseoverPhone">
                拨打电话{{
                  isShowPhone
                  ? data.userInformation && data.userInformation.phone
                  : ""
                }}
              </div>
              <div class="one-detail-btn" @click="chat">在线聊天</div>
            </div>
          </div>
        </div>
      </template>
    </div>
    <floor></floor>
    <chat ref="chats"></chat>

  </div>
</template>
<script>
import floor from "@/components/floor";
import heads from "@/components/head";
import ceList from "@/components/ceList.vue";
import titlesearch from "@/components/titlesearch.vue";
import recommended from "../comp/recommended.vue";
import inviteItem from "../comp/item.vue";
import chat from "@/components/chat";

import { mapMutations, mapState } from "vuex";
export default {
  components: {
    floor,
    heads,
    ceList,
    titlesearch,
    recommended,
    inviteItem,
    chat
  },
  data() {
    return {
      searchKeyword: "",
      showDetail: false,
      tabIndex: 1,
      manage: false,
      compilestate: false,
      zbc: false,
      shouyeShow: false,
      shangjiaShow: false,
      xuan: 9,
      leibie: 2,
      radioCities: "",
      checkboxShow: false,
      user: {},
      msgpage: {
        pageSize: 10,
        pageNo: 1
      },
      msgList: [],
      msgtotal: 0,
      select: false,
      list: [],
      Recommend: [],
      curResume: {},
      isShowPhone: false,
      data: {}
    };
  },
  computed: {
    ...mapState({
      msgCount: state => state.msgCount
    })
  },
  async mounted() {
    await this.initMap();
    this.getUser();

    this.statusInformation();
    this.getRecommend();
    localStorage.setItem("needed", 0);
  },
  methods: {
    ...mapMutations(["setMsgCount"]),
    initMap() {
      let data = {
        key: "ZYIBZ-6VVRW-NCURN-O6GZO-2VRAH-KIBJV",
        output: "jsonp"
      };
      return this.$jsonp(
        "https://apis.map.qq.com/ws/location/v1/ip",
        data
      ).then(data => {
        let lat = data.result.location.lat;
        let lng = data.result.location.lng;
        // 经度
        this.longitude = data.result.location.lng;
        // 维度
        this.latitude = data.result.location.lat;
      });
    },
    chat(userId, id) {
      this.chatzc({
        userId: this.data.userInformation.id,
        id: this.data.id
      });
    },
    mouseoverPhone() {
      this.checkLogin(() => {
        this.insertCallRecord({
          userId: JSON.parse(localStorage.getItem("userInfo")).id,
          associationId: this.data.id,
          businessType: 4,
          telephoneNumber: this.data.userInformation.phone,
          callType: 8,
        });
        this.isShowPhone = !this.isShowPhone;
      });
    },
    // 收到简历
    sdnotesDetail(id) {
      let that = this;
      this.$getHttp(
        "/api/mobile/personnelOwner/getResumeDeliveryRecordDetails",
        {
          id
        }
      ).then(res => {
        this.data = res.resumeDeliveryRecordDetails;
        this.curResume = res.resumeDeliveryRecordDetails;
        this.showDetail = true;
      });
    },
    // 获取简历
    hqnotesDetail(id) {
      let that = this;
      this.$getHttp("/api/mobile/personnelOwner/getObtainResumeRecordById", {
        id
      }).then(res => {
        this.data = res.obtainResumeRecords;
        this.curResume = res.obtainResumeRecords;

        this.showDetail = true;
      });
    },
    detail(item, index = this.tabIndex) {
      if (index == 2) {
        // 如果是投递记录
        this.openUrlb("/invite/invitedetail", { id: item.recruitmentInformationDTO.id });
        return;
      }
      if (index == 1) {
        // 收到简历
        // console.log("收到简历", item);
        if (item.pictureAttachment) {
          this.sdnotesDetail(item.id);
        } else {
          this.goResumeOne(
            {
              id: item.id,
              indextd: 1
            },
            item
          );
        }
      } else if (index == 3) {
        // 获取简历
        // console.log("获取简历", item);
        if (item.pictureAttachment) {
          this.hqnotesDetail(item.id);
        } else {
          this.goResumeOne(
            {
              id: item.resumeId,
              indextd: 2
            },
            item
          );
        }
      }

      if (index == 1) {
        if (item.receivingStatus != 1) {
          this.read(item.id);
        }
      }
    },
    // 已读消息
    read(id) {
      let that = this;
      this.$postHttp("/api/mobile/personnelOwner/markRead", {
        id: id,
        markerBy: this.user.id
      }).then(res => { });
    },
    // 判断用户身份
    statusInformation() {
      if (
        this.userInfo.personalRecruitmentStatus != 1 &&
        this.userInfo.enterpriseRecruitmentStatus != 1
      ) {
        this.list = [{ num: 2, text: "投递记录" }];
        this.tabIndex = 2;
      } else if (
        this.userInfo.personalRecruitmentStatus == 1 &&
        this.userInfo.enterpriseRecruitmentStatus != 1
      ) {
        this.list = [
          { num: 1, text: "收到简历" },
          { num: 2, text: "投递记录" }
        ];
        this.tabIndex = 1;
      } else if (this.userInfo.enterpriseRecruitmentStatus == 1) {
        this.list = [
          { num: 1, text: "收到简历" },
          { num: 3, text: "获取简历" }
        ];
        this.tabIndex = 1;
      }
    },
    tabClick(num) {
      // console.log("1111111");
      this.getRecommend(true);
    },
    getRecommend(flag = false) {
      if (flag) {
        this.msgpage.pageNo = 1;
      }
      this.Recommend = [];
      if (this.tabIndex == 1) {
        this.sdnotes();
      } else if (this.tabIndex == 2) {
        this.tdnotes();
      } else if (this.tabIndex == 3) {
        this.hqnotes();
      }
    },
    // 获取收到简历数据
    sdnotes() {
      let that = this;
      this.$getHttp("/api/mobile/personnelOwner/getResumeReceivedTabulation", {
        userId: this.userInfo.id,
        longitude: this.longitude,
        latitude: this.latitude,
        keyword: this.searchKeyword,

        ...this.msgpage
      }).then(res => {
        res.resumeReceivedTabulation.pageList.forEach(v => {
          v.active = false;
          v.choose = false;
        });
        this.Recommend = res.resumeReceivedTabulation.pageList;
        this.msgtotal = res.resumeReceivedTabulation.pageCount;
      });
    },
    // 获取投递记录数据
    tdnotes() {
      let that = this;
      this.$getHttp("/api/mobile/personnelOwner/getDeliveryRecordTabulation", {
        userId: this.userInfo.id,
        longitude: this.longitude,
        latitude: this.latitude,
        keyword: this.searchKeyword,

        ...this.msgpage
      }).then(res => {
        res.deliveryRecordTabulation.pageList.forEach(v => {
          v.active = false;
          v.choose = false;
        });
        this.Recommend = res.deliveryRecordTabulation.pageList;
        this.msgtotal = res.deliveryRecordTabulation.pageCount;
      });
    },
    // 获取简历数据
    hqnotes() {
      let that = this;
      this.$getHttp("/api/mobile/personnelOwner/getObtainResumeRecords", {
        userId: this.userInfo.id,
        longitude: this.longitude,
        latitude: this.latitude,
        keyword: this.searchKeyword,

        ...this.msgpage
      }).then(res => {
        res.obtainResumeRecords.pageList.forEach(v => {
          v.active = false;
          v.choose = false;
        });
        this.Recommend = res.obtainResumeRecords.pageList;
        this.msgtotal = res.obtainResumeRecords.pageCount;
      });
    },

    selectColl(type) {
      console.log("typetypetypetype", type);
      this.msgList.map(e => {
        e.choose = type;
      });
    },
    operate(flag) {
      if (this.compilestate) {
        this.choosehouse("empty");
      } else {
      }
      if (flag) {
        this.compilestate = false;
        return false;
      }
      this.compilestate = !this.compilestate;
    },
    choosehouse(id) {
      this.Recommend.map(item => {
        if (item.id == id) {
          item.choose = !item.choose;
        }
      });
      this.select = this.msgList.every(e => {
        return e.choose;
      });
    },
    clearAll() {
      let that = this;
      if (this.showDetail) {
        var ids = this.curResume.id;
      } else {
        var arr = this.Recommend.filter(item => item.choose);
        var ids = arr.map(item => item.id).join(",");
      }
      console.log('this.curResumethis.curResume', this.curResume)
      if (!ids) {
        this.myErrorMessage("请选择删除记录");
        return false;
      }
      this.$confirm("此操作将删除此记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let urlArr = [
            {
              url: "/api/mobile/personnelOwner/dislodgeReceivedResume"
            },
            {
              url: "/api/mobile/personnelOwner/dislodgePostingResume"
            },
            {
              url: "/api/mobile/personnelOwner/deleteGetResumeRecord"
            }
          ];
          let url = urlArr[this.tabIndex - 1].url;
          if (this.delLoading) {
            return false;
          }
          this.delLoading = true;
          this.$postHttp(url, {
            ids: ids,
            userId: this.userInfo.id
          }).then(data => {
            if (data.code == 200) {
              setTimeout(() => {
                that.mySuccessMessage(data.msg);
                this.delLoading = false;
                this.showDetail = false;
              }, 200);
              that.getRecommend(true);
              that.compilestate = false;
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
          this.compilestate = false;
          this.delLoading = false;
        });
    },

    getUser() {
      let user = JSON.parse(localStorage.getItem("userInfo"));
      if (user != null) {
        this.loginstate = true;
        this.user = user;
        this.userInfo = user;
        // this.getMsgInfo();
      } else {
        this.loginstate = false;
        this.$message({
          message: "请登录！",
          type: "error",
          offset: 120,
          duration: 2000
        });
        this.$router.push("/");
      }
    },
    add0(m) {
      return m < 10 ? "0" + m : m;
    },
    getMsgInfo(cab) {
      this.$getHttp("/mob/user/getExamineInfo", this.msgpage).then(data => {
        if (data.code == 200) {
          data.page.result.map(item => {
            item.choose = false;
            item.date = this.format(item.create_date).split(" ")[0];
            item.time = this.format(item.create_date).split(" ")[1];
          });
          this.msgList = data.page.result;
          this.msgtotal = data.page.count;
          cab && cab();
        }
      });
    },
    format(shijianchuo) {
      //shijianchuo是整数，否则要parseInt转换
      var time = new Date(shijianchuo);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return (
        y +
        "年" +
        this.add0(m) +
        "月" +
        this.add0(d) +
        "日 " +
        this.add0(h) +
        ":" +
        this.add0(mm)
      );
    },
    audit(item) {
      let that = this;
      console.log(item);
      if (item.type == "2" && item.examine_status == "0") {
        let data = {};
        let url;
        if (item.business_type == 1) {
          data = {
            shopName: this.user.shopName,
            shopId: this.user.shopId,
            userId: item.create_by,
            id: item.id,
            examineStatus: 0,
            remark: "",
            createBy: item.create_by
          };
          url = "/mob/user/merchantAudit";
        } else {
          data = {
            reviewedBy: this.user.id,
            auditee: item.create_by,
            storeId: this.user.shopId,
            auditStatus: 0,
            systemMessagesId: item.id,
            refuseReason: ""
          };
          url = "/api/mobile/vehicleOwner/salesConsultantReview";
        }

        this.$confirm(item.content, "提示", {
          confirmButtonText: "同意",
          cancelButtonText: "拒绝"
        })
          .then(() => {
            delete data.remark;
            if (item.business_type == 1) {
              data.examineStatus = 1;
            } else if (item.business_type == 2) {
              data.auditStatus = 1;
            }
            this.$postHttp(url, data).then(data => {
              if (data.code == 200) {
                this.$message({
                  message: "审核成功",
                  type: "success"
                });
                this.getMsgInfo();
              }
            });
          })
          .catch(() => {
            this.$prompt("请输入拒绝原因", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消"
            })
              .then(({ value }) => {
                if (item.business_type == 1) {
                  data.examineStatus = 2;
                } else if (item.business_type == 2) {
                  data.auditStatus = 2;
                }

                data.remark = value == null ? "" : value;
                this.$postHttp(url, data).then(data => {
                  if (data.code == 200) {
                    this.$message({
                      message: data.msg,
                      type: "success"
                    });
                    this.getMsgInfo();
                  }
                });
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "取消审核"
                });
              });
          });
      } else {
        this.$alert(item.content, "系统消息", {
          confirmButtonText: "确定",
          showClose: false,
          callback: action => {
            that
              .$postHttp("mob/chatrecord/readNotice", {
                id: item.id
              })
              .then(res => {
                if (res.code == 200) {
                  that.getMsgInfo();
                  that
                    .$getHttp("/mob/user/getIsReadMsg", {
                      isRead: 2,
                      examineStatus: 2,
                      userId: that.user.id
                    })
                    .then(data2 => {
                      if (data2.code == 200) {
                        // localStorage.setItem("msgCount", data2.result);
                        this.setMsgCount(data2.result);
                      }
                    });
                }
              });
          }
        });
      }
    },
    readAll() {
      let that = this;
      that
        .$postHttp("/mob/chatrecord/readChatAll", {
          receiver: that.user.id
        })
        .then(data2 => {
          if (data2.code == 200) {
            // localStorage.setItem("msgCount", data2.result);
            that.getMsgInfo(() => {
              this.setMsgCount(0);
            });

            // this.compilestate = false;
          }
        });
    },
    msgCurrentChange(e) {
      this.msgpage.pageNo = e;
      this.operate(true);
      this.getRecommend();
    },

    shouye() {
      this.zbc = true;
      this.shouyeShow = true;
      document.documentElement.style.overflow = "hidden";
    },
    quedingShouye() {
      this.zbc = false;
      this.shouyeShow = false;
      document.documentElement.style.overflow = "";
    },
    guanShouye() {
      this.zbc = false;
      this.shouyeShow = false;
      document.documentElement.style.overflow = "";
    },
    shangjia() {
      this.zbc = true;
      this.shangjiaShow = true;
      document.documentElement.style.overflow = "hidden";
    },
    quedingShangjia() {
      this.zbc = false;
      this.shangjiaShow = false;
      document.documentElement.style.overflow = "";
    },
    guanShangjia() {
      this.zbc = false;
      this.shangjiaShow = false;
      document.documentElement.style.overflow = "";
    },
    xuanClick(num) {
      this.xuan = num;
    },
    leibieClick(num) {
      this.leibie = num;
    },
    binaji() {
      this.checkboxShow = !this.checkboxShow;
    }
  }
};
</script>
<style lang="less" scoped>
.toread-wrap {
  position: relative;

  .toread {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 16px;
    height: 16px;
    background: red;
    border-radius: 50%;
  }
}

.con {
  .title1 {
    display: flex;
    padding: 25px 34px;
    color: #333333;
    font-size: 20px;
    align-items: center;
    border-bottom: #e0e0e0 1px solid;
    justify-content: space-between;
  }
}

.box {
  position: relative;
  padding-bottom: 200px;
}

.con {
  display: inline-block;
  box-sizing: border-box;
  vertical-align: top;
  width: 940px;
  color: #333;
  border: 1px solid #d0d0d0;
  border-radius: 6px;

  // padding: 24px 40px;
  .new-title {
    height: 50px;
    background: #f2f2f2;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    font-size: 24px;
    font-weight: 500;
    color: #666666;
    line-height: 50px;
    padding-left: 40px;
  }

  .list {
    padding: 0 40px;

    .li {
      position: relative;
      line-height: 40px;

      display: flex;
      // padding: 30px 20px 16px 20px;
      // border-bottom: 1px solid #e0e0e0;

      // justify-content: space-between;
      box-sizing: border-box;

      .operate-btn {
        width: 92px;
        height: 40px;
        border-radius: 4px 4px 4px 4px;
        opacity: 1;
        border: 1px solid #64b6a8;

        font-size: 20px;
        font-weight: 400;
        color: #64b6a8;
        line-height: 40px;
        text-align: center;
        cursor: pointer;
      }
    }
  }

  .fenye {
    width: 100%;
    height: 50px;
    text-align: center;
    margin-bottom: 50px;
  }

  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #64b6a8;
  }
}

.gerenBox {
  width: 1200px;
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 32px;
  margin-bottom: 45px;

  .geren {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    width: 240px;
    min-height: 820px;
    margin-right: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;

    img {
      width: 110px;
      height: 110px;
      border-radius: 50%;
      margin-top: 40px;
      margin-left: 65px;
    }

    p {
      width: 100%;
      text-align: center;
      font-size: 18px;
      color: #333333;
      margin-top: 12px;
      margin-bottom: 40px;
    }

    .list {
      position: relative;
      width: 100%;

      .li {
        width: 209px;
        height: 50px;
        line-height: 50px;
        margin-left: 30px;
        text-indent: 40px;
        font-size: 18px;
        color: #333;
        border-radius: 25px 0 0 25px;
        cursor: pointer;
      }

      .xuan {
        background-color: #64b6a8;
        color: #fff;
      }
    }

    .kuai {
      width: 100%;
      height: 6px;
      background-color: #64b6a8;
      position: absolute;
      bottom: 0;
    }
  }
}

.one-detail {
  position: relative;

  .one-detail-img {
    position: relative;
    top: 30px;
    transform: translateX(-50%);
    left: 50%;
    width: 611px;
    height: 882px;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    object-fit: cover;
  }

  .one-detail-btn-wrap {
    display: flex;
    margin: 40px 0;
    justify-content: center;

    .one-detail-btn {
      text-align: center;
      min-width: 240px;
      // padding: 0 8px;
      height: 50px;
      border-radius: 6px 6px 6px 6px;
      opacity: 1;
      border: 1px solid #64b6a8;
      white-space: nowrap;
      font-size: 20px;
      font-weight: 500;
      color: #64b6a8;
      line-height: 50px;
      cursor: pointer;

      &.active {
        color: #ffffff;
        background-color: #64b6a8;
        border: none;
      }

      &+.one-detail-btn {
        margin-left: 60px;
      }
    }
  }
}
</style>
